Skip to content

gh-146609: Add colour to timeit CLI output#146610

Open
hugovk wants to merge 6 commits intopython:mainfrom
hugovk:3.15-timeit-colour
Open

gh-146609: Add colour to timeit CLI output#146610
hugovk wants to merge 6 commits intopython:mainfrom
hugovk:3.15-timeit-colour

Conversation

@hugovk
Copy link
Copy Markdown
Member

@hugovk hugovk commented Mar 29, 2026

Standard and verbose:

./python.exe -m timeit "'-'.join(str(n) for n in range(100))"
./python.exe -m timeit --verbose "'-'.join(str(n) for n in range(100))"
image

With a warning:

./python.exe -m timeit "import time, random; time.sleep(random.random() * 0.5)"
image

As usual, environment variables can control colour output.


📚 Documentation preview 📚: https://cpython-previews--146610.org.readthedocs.build/

UserWarning, '', 0)

print(file=sys.stderr)
warnings.warn_explicit(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this very busy currently, maybe it could just be one colour for warnings?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do. All yellow?

image

I think there is some value highlighting the best/worst somehow. Here's some other toned-down variations.

No bold:

image

Just best/worst diff colour:

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just best/worst diff colour:

That seems reasonable to me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

Co-authored-by: Stan Ulbrych <stan@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants